package cn.psvmc.cxzapi.service.customer;

import cn.psvmc.cxzapi.mapper.customer.TCustomerMapper;
import cn.psvmc.cxzapi.mapper.store.TCouponMapper;
import cn.psvmc.cxzapi.service.alipay.AlipayCreate;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ywx
 * @className TCustomerMessageService
 * @description
 * @date 2024/12/18 21:38
 **/
@Service
public class TCustomerMessageService {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TCouponMapper tCouponMapper;

    /**
     * @Description 查询消息订阅关系
     * @Date 2024/12/18 21:51
     * @Author YWX
     * @Param [userid, templateIds]
     * @Return boolean
     **/
    public boolean queryMessageTemplateSubscribe(int userid, List<String> templateIds) {
        if (!ToolUtils.isTrueInteger(userid)) {
            return false;
        }
        String openId = tCustomerMapper.getOpenIdByCustomerId(userid);
        if (ToolUtils.isEmpty(openId)) {
            return false;
        }
        return AlipayCreate.messagetemplateSubscribeQuery(openId, templateIds);
    }

    /**
     * @Description 活动领取咨询
     * @Date 2025/1/4 0:20
     * @Author YWX
     * @Param [userid]
     * @Return java.lang.Object
     **/
    public Object activityConsult(int userid) {
        if (!ToolUtils.isTrueInteger(userid)) {
            return new ArrayList<>();
        }
        String openId = tCustomerMapper.getOpenIdByCustomerId(userid);
        List<String> activityIds = tCouponMapper.listActivityIdByCustomerId(userid);
        if (ToolUtils.isListEmpty(activityIds) || ToolUtils.isEmpty(openId)) {
            return new ArrayList<>();
        }
        return AlipayCreate.activityConsult(activityIds, openId);
    }
}
